package com.greatchn.no_session_auth_code.web.po;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.provider.ClientDetails;

import java.util.*;

/**
 * @CustomClientDetails: 自定义客户端详情
 * @author: ZBoHang
 * @time: 2023/2/17 10:45
 */
@Data
@Accessors(chain = true)
public class CustomClientDetails implements ClientDetails {

    private String cusClientId;
    private String cusClientSecret;
    private Set<String> cusAuthorizedGrantTypes;
    private Set<String> cusScope;
    private Set<String> cusResourceIds;
    private boolean cusAutoApprove;
    private Set<String> cusRegisteredRedirectUri;
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private List<GrantedAuthority> cusAuthorities = Collections.emptyList();

    public void setCusAuthorities(Collection<GrantedAuthority> cusAuthorities) {
        this.cusAuthorities = new ArrayList<>(cusAuthorities);
    }

    @Override
    public String getClientId() {
        return this.cusClientId;
    }

    @Override
    public Set<String> getResourceIds() {
        return this.cusResourceIds;
    }

    @Override
    public boolean isSecretRequired() {
        return this.cusClientSecret != null;
    }

    @Override
    public String getClientSecret() {
        return this.cusClientSecret;
    }

    @Override
    public boolean isScoped() {
        return this.cusScope != null && !this.cusScope.isEmpty();
    }

    @Override
    public Set<String> getScope() {
        return this.cusScope;
    }

    @Override
    public Set<String> getAuthorizedGrantTypes() {
        return this.cusAuthorizedGrantTypes;
    }

    @Override
    public Set<String> getRegisteredRedirectUri() {
        return this.cusRegisteredRedirectUri;
    }

    @Override
    public Collection<GrantedAuthority> getAuthorities() {
        return this.cusAuthorities;
    }

    @Override
    public Integer getAccessTokenValiditySeconds() {
        return null;
    }

    @Override
    public Integer getRefreshTokenValiditySeconds() {
        return null;
    }

    @Override
    public boolean isAutoApprove(String scope) {
        return this.cusAutoApprove;
    }

    @Override
    public Map<String, Object> getAdditionalInformation() {
        return null;
    }
}
